package com.example.nophase.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.nophase.R;
import com.example.nophase.entity.OaCommonAuditBean;

import java.text.SimpleDateFormat;
import java.util.List;

public class OaCommonAdultListAdapter extends BaseAdapter {
    List<OaCommonAuditBean> list;
    Context context;
    String appType;



    public OaCommonAdultListAdapter(List<OaCommonAuditBean> list, Context context, String appType) {
        this.list = list;
        this.context = context;
        this.appType = appType;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        if (position == getCount() || list == null) {
            return null;
        }
        return list.get(position);

    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {

        View view = LayoutInflater.from(context).inflate(R.layout.adult_list_item, null);
        TextView username = view.findViewById(R.id.adult_username);
        TextView adultdate = view.findViewById(R.id.adult_date);
        ImageView adultstatus = view.findViewById(R.id.adult_status);
        TextView adultdepartment = view.findViewById(R.id.adult_department);

        OaCommonAuditBean item = list.get(position);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formatStr = formatter.format(item.getCreateDate());
        username.setText(item.getName());

        if (item.getActivitiname().equals("业务/总部部门审核")) {
            if (appType.equals("区域申请")) {
                adultdepartment.setText("区域/城市公司总审批");
            } else if (appType.equals("职能部门")) {
                adultdepartment.setText("部门经理审批");
            }


        } else {
            adultdepartment.setText(item.getActivitiname());
        }


//        adultmsg.setText(list.get(position).getAdvice().toString());
        adultdate.setText(formatStr);
        if (item.getResult() == 1) {
            adultstatus.setBackgroundResource(R.drawable.adult_success);
        } else {
            adultstatus.setBackgroundResource(R.drawable.adult_error);
        }


        return view;
    }


}
